﻿using System;
using fastCSharp;

namespace diantou.web.enterprise
{
    /// <summary>
    /// 问题集合
    /// </summary>
    abstract class questionList<viewType> : examPermissionView<viewType>
        where viewType : questionList<viewType>
    {
        /// <summary>
        /// 考试
        /// </summary>
        [fastCSharp.emit.webView.clearMember]
        protected diantou.examDataAccess.exam exam;
        /// <summary>
        /// 问题集合
        /// </summary>
        [fastCSharp.emit.webView.clearMember]
        protected examQuestion[] questions;
        /// <summary>
        /// 考试类型
        /// </summary>
        protected abstract dataModel.examQuestion.type type { get; }
        /// <summary>
        /// 是否存在公共题目查看权限错误
        /// </summary>
        protected bool isPublicError;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="page"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        protected bool loadView(int examId, int page, int topicId, bool isPublic, diantou.dataAccess.problem.showType showType, diantou.examDataAccess.examQuestion.sort sort, bool isAsc)
        {
            if (examId != 0)
            {
                exam = diantou.examDataAccess.clientCache.GetExam(examId, currentUser, false);
                if (exam == null) examId = 0;
            }
            questions = diantou.examDataAccess.tcpCall.examQuestion.get(currentUser.Id, currentUser.IsChangeVisit, topicId, type, isPublic, showType, sort, isAsc, pageInfo.Size = fastCSharp.config.pub.Default.PageSize, pageInfo.Page = page, out pageInfo.Count, out isPublicError)
                .Value.getArray(question => new examQuestion { ExamId = examId, Question = question });
            if (isPublic)
            {
                foreach(examQuestion question in questions)
                {
                    switch(question.Question.Type)
                    {
                        case dataModel.examQuestionBase.type.Radio:
                            question.Question.Answer = -1;
                            break;
                        case dataModel.examQuestionBase.type.MultipleChoice:
                            question.Question.AnswerContent = string.Empty;
                            break;
                    }
                }
            }
            return true;
        }
    }
}
